package com.springboot.controller;

import com.springboot.model.AssistantListFormKey;
import com.springboot.model.UserLoginForm;
import com.springboot.service.DoctorSetAssistantService;
import com.springboot.service.DoctorViewNewAssistantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

/**
 * 本控制台用于医生设置新的助理
 */
@Controller
public class DoctorSetAssistantController {
    @Autowired
    DoctorSetAssistantService doctorSetAssistantService;
    @Autowired
    DoctorViewNewAssistantService doctorViewNewAssistantService;
    /**
     * 医生设置新的助理
     */
    @CrossOrigin
    @RequestMapping(value = "/doctorSetAssistant")
    public @ResponseBody
    String doctorSetAssistant(@RequestParam("doctorTel") String doctorTel,
                              @RequestParam("assistantTel") String assistantTel) {
        System.out.println("医生设置新的助理");
        try {
            UserLoginForm doctor=doctorSetAssistantService.findUserByTel(doctorTel);
            UserLoginForm assistant=doctorSetAssistantService.findUserByTel(assistantTel);
            int doctorId=doctor.getUserId();
            int assistantId=assistant.getUserId();
            ArrayList<AssistantListFormKey> assistantListFormKeys=doctorViewNewAssistantService.findAssistantByDoctor(doctorId);
            if(assistantListFormKeys.size()>=3)
            {
                return "Full";
            }
            AssistantListFormKey assistantListFormKey=new AssistantListFormKey();
            assistantListFormKey.setDoctorId(doctorId);
            assistantListFormKey.setAssistantId(assistantId);
            doctorSetAssistantService.insertIntoAssistantList(assistantListFormKey);
            return "True";
        } catch (Exception e) {
            return "False";
        }
    }
}
